﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

using Framework.GameStateManagment;

namespace Framework.Graphics
{
    public class Camera
    {
        private static SpriteBatch _spriteBatch;
        private static Vector2 _position;
        private static Rectangle _screen;

        public static SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }
            set { _spriteBatch = value; }
        }

        public static void Init(SpriteBatch sb, Vector2 SizeofScreen)
        {
            _position = new Vector2(SizeofScreen.X / 2, SizeofScreen.Y / 2);
            _screen = new Rectangle(0, 0, (int)SizeofScreen.X, (int)SizeofScreen.Y);
            _spriteBatch = sb;
        }

        public static void TryDraw(Texture2D texture, Vector2 position, Color color)
        {
            Rectangle recTemp = new Rectangle((int)Math.Round(position.X + Input.Movement.X, 0), (int)Math.Round(position.Y + Input.Movement.Y, 0),
                texture.Width, texture.Height);
            if (_screen.Intersects(recTemp))
            {
                _spriteBatch.Draw(texture, (position + Input.Movement), color);
            }
            //_SpriteBatch.Draw(texture, (position + Input.Movement), color);

        }

        public static void TryDrawCasters(Texture2D texture, Vector2 position, Color color)
        {
            Rectangle recTemp = new Rectangle((int)Math.Round(position.X + Input.Movement.X, 0), (int)Math.Round(position.Y + Input.Movement.Y, 0),
                texture.Width, texture.Height);
            if (_screen.Intersects(recTemp))
            {
                // _SpriteBatch.Draw(texture, (position), color);
            }
            _spriteBatch.Draw(texture, (position + Input.Movement), color);

        }

        public static void TryDraw(Texture2D texture, Vector2 position, Nullable<Rectangle> sourceRectangle,
            Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
        {
            _spriteBatch.Draw(texture, (position + Input.Movement), sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
        }

        public static void TryDraw(RenderTarget2D target, Vector2 position, Color color)
        {
            _spriteBatch.Draw(target, (position), color);
        }

        public static void DrawWithoutMovement(Texture2D texture, Vector2 position, Color color)
        {
            Rectangle recTemp = new Rectangle((int)Math.Round(position.X + Input.Movement.X, 0), (int)Math.Round(position.Y + Input.Movement.Y, 0),
                texture.Width, texture.Height);
            if (_screen.Intersects(recTemp))
            {
                _spriteBatch.Draw(texture, (position + Input.Movement), color);
            }
            //_SpriteBatch.Draw(texture, (position + Input.Movement), color);

        }

        public static void DrawWithoutMovement(Texture2D texture, Vector2 position, Nullable<Rectangle> sourceRectangle,
    Color color, float rotation, Vector2 origin, float scale, SpriteEffects effects, float layerDepth)
        {
            _spriteBatch.Draw(texture, (position), sourceRectangle, color, rotation, origin, scale, effects, layerDepth);
        }

        public static void Update(Vector2 movement)
        {
            if (GameStateManagment.GameStateManagment.GameState != 3)
            {
                _position += movement;
            }
        }

        public static void CustomUpdate(Vector2 movement)
        {
            _position += movement;
        }

    }
}
